'''
按键
'''

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

class QPushButtonDemo(QDialog):
    def __init__(self):
        super(QPushButtonDemo, self).__init__()
        self.initUI()
        self.show()
    def initUI(self):
        self.setWindowTitle("按键")
        self.resize(300, 300)
        layout = QVBoxLayout()

        self.textEidt = QTextEdit()
        self.btn1 = QPushButton("OK")
        self.btn1.setChecked(True)
        self.btn1.toggle()
        self.btn1.clicked.connect(lambda:self.whichButton(self.btn1))
        # self.btn1.clicked.connect(self.buttonState)

        self.btn2 = QPushButton()
        self.btn2.setText("图像按钮")
        self.btn2.setIcon(QIcon(QPixmap('./python.png')))
        self.btn2.clicked.connect(lambda: self.whichButton(self.btn2))

        layout.addWidget(self.textEidt)
        layout.addWidget(self.btn1)
        layout.addWidget(self.btn2)
        self.setLayout(layout)

    def buttonState(self):
        if self.btn1.isChecked():
            print("OK")
        else:
            print("---")

    def whichButton(self, btn):
        self.textEidt.setPlainText(btn.text())
if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = QPushButtonDemo()

    sys.exit(app.exec_())